import React from "react";
import App from "next/app";
import Router from "next/router";
import withReduxStore from "@/redux/lib/with-redux-store.js";
import { Provider, useSelector } from "react-redux";

import { ClientLayout } from "@/layout";
import { NProgress } from "@components/NProgress";
import "viewerjs/dist/viewer.css";
import "highlight.js/styles/monokai-sublime.css";
import "@/theme/antd.less";
import "@/theme/reset.scss";
import "@/theme/markdown.scss";

let lastUrl;

// const addView = (url) => {
//   if (/localhost/.test(url)) {
//     return;
//   }
//   ViewApi.addView({ url });
// };
class MyApp extends App {
  static getInitialProps = async (ctx) => {
    const [appProps] = await Promise.all([
      // 获取所有页面公共数据
      App.getInitialProps(ctx),
    ]);
    return { ...appProps };
  };

  componentDidMount() {
    try {
      const el = document.querySelector("#holderStyle");
      el.parentNode.removeChild(el);
    } catch (e) {}
  }

  render() {
    const { Component, pageProps, setting = {}, store } = this.props as any;
    const { needLayoutFooter = true } = pageProps;
    return (
      <Provider store={store}>
        <ClientLayout setting={setting} needFooter={needLayoutFooter}>
          <style
            id="holderStyle"
            dangerouslySetInnerHTML={{
              __html: ` * {
      transition: none !important;
    }`,
            }}
          ></style>
          <NProgress color={"#ff0064"} />
          <Component {...pageProps} setting={setting} />
        </ClientLayout>
      </Provider>
    );
  }
}

export default withReduxStore(MyApp);
